<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>迭代器-使用</title>
</head>
<body>
<script>
    //自定义遍历对象

    const classRoom = {
        name: 'math',
        students: [
            'zhangSan',
            'liSi',
            'wangWu'
        ],
        [Symbol.iterator]() {
            let index = 0;
            let that = this;
            return {
                next: () => {
                    if (index < that.students.length) {
                        let result = {value: that.students[index], done: false}
                        index++
                        return result;
                    } else {
                        return {
                            value:undefined, done: true
                        }
                    }
                }
            }
        }
    }
    for (let classRoomElement of classRoom) {
        console.log(classRoomElement)
    }
</script>
</body>
</html>